//
//  ViewController.m
//  ScrollTopAndCont
//
//  Created by xingshuai on 2020/11/5.
//

#import "ViewController.h"

#import "JXCategoryView.h"
#import "TwoViewController.h"
#import "JXCategoryTitleView.h"

@interface ViewController () <JXCategoryListContainerViewDelegate, JXCategoryViewDelegate>

@property (nonatomic,strong) JXCategoryTitleView *topTitleView;
@property (nonatomic,strong) JXCategoryListContainerView *listContainerView;
@property (nonatomic,strong) NSMutableArray *titles;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.titles = [[NSMutableArray alloc]initWithObjects:@"周一",@"sdfjasdlfka",@"帅",@"kkk",@"周二",@"星期三",@"周六",@"周日",@"周四",@"星期五", nil];
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self creatUI];
    
}

-(void)creatUI {
    // 标签
    self.topTitleView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0, 44, self.view.frame.size.width, 40)];
    self.topTitleView.backgroundColor = [[UIColor orangeColor] colorWithAlphaComponent:0.3];
    self.topTitleView.delegate = self;
    self.topTitleView.titleFont = [UIFont systemFontOfSize:16];
    self.topTitleView.titleSelectedFont = [UIFont systemFontOfSize:17];
    self.topTitleView.titleColor = [UIColor grayColor];
    self.topTitleView.titleSelectedColor = [UIColor redColor];
    self.topTitleView.titleColorGradientEnabled = YES;
    self.topTitleView.titleLabelZoomEnabled = NO;
    self.topTitleView.contentScrollViewClickTransitionAnimationEnabled = NO;
    self.topTitleView.titles = self.titles;
    self.topTitleView.contentEdgeInsetLeft = 15;
    self.topTitleView.contentEdgeInsetRight = 15;
    
    // 过渡方式
    JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
    lineView.indicatorColor = [UIColor redColor];
    lineView.lineStyle = JXCategoryIndicatorLineStyle_Normal;
    lineView.indicatorHeight = 2;
    lineView.verticalMargin = 1;
    self.topTitleView.indicators = @[lineView];
    [self.view addSubview:self.topTitleView];
    
    // 滑动内容关联
    self.listContainerView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_ScrollView delegate:self];
    self.listContainerView.frame = CGRectMake(0, 84, self.view.frame.size.width, self.view.frame.size.height-184);
    [self.view addSubview:self.listContainerView];
    // 关联到 categoryView
    self.topTitleView.listContainer = self.listContainerView;
}

#pragma mark - JXCategoryListContainerViewDelegate
// 返回列表的数量
- (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView {
    return self.titles.count;
}

// 根据下标 index 返回对应遵守并实现 `JXCategoryListContentViewDelegate` 协议的列表实例
- (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index {
    
    // 标签对应的控制器可以在这里设置
    TwoViewController *VC = [[TwoViewController alloc]init];
    VC.str = [self.titles objectAtIndex:index];
    return VC;
}

@end
